package com.jeespring.elasticsearch.service.impl;

import com.jeespring.elasticsearch.dto.ItemDTO;
import com.jeespring.elasticsearch.dto.UserIndexDTO;
import com.jeespring.elasticsearch.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.IndexOperations;
import org.springframework.data.elasticsearch.core.document.Document;
import org.springframework.stereotype.Service;

/**
 * @description SearchService
 * @author 张朝阳
 * @date 2021/9/17 17:15
 */
@Service
public class SearchServiceImpl implements SearchService {

    @Autowired
    private ElasticsearchRestTemplate elasticTemplate;

    @Override
    public void createItemIndex(){
        elasticTemplate.indexOps(ItemDTO.class).create();;
    }

    @Override
    public void createUserIndex(){
        elasticTemplate.indexOps(UserIndexDTO.class).create();
        Document mapping = elasticTemplate.indexOps(UserIndexDTO.class).createMapping(UserIndexDTO.class);
        elasticTemplate.indexOps(UserIndexDTO.class).putMapping(mapping);

    }
}
